package singleThread;

import controller.MonteCarloSimulation;
import gui.MainWindow;



public class MonteCarloSingleThread implements Runnable{
	
	public static final int nSimulations = 100000;
	private MainWindow mw;
	
	public MonteCarloSingleThread(MainWindow mw){
		this.mw = mw;
	}

	@Override
	public void run(){
		
		double start = System.currentTimeMillis();
		double Sum = 0;
		
		for (int i=0 ; i< nSimulations ;i++)
		{
			Sum = Sum+ MonteCarloSimulation.singleSimulation((String)mw.callPutFlag.getSelectedItem(), Double.valueOf((String)mw.s.getSelectedItem()),
					Double.valueOf((String)mw.x.getSelectedItem()), Double.valueOf((String)mw.t.getSelectedItem()), Double.valueOf((String)mw.r.getSelectedItem()), Double.valueOf((String)mw.b.getSelectedItem()), Double.valueOf((String)mw.v.getSelectedItem()), Integer.valueOf((String)mw.nSteps.getSelectedItem()));
			mw.pb.setValue(Math.round(i*100/nSimulations));
		}
		
		double sum = MonteCarloSimulation.average(Double.valueOf((String)mw.r.getSelectedItem()), Double.valueOf((String)mw.t.getSelectedItem()), Sum, nSimulations);
		mw.pb.setValue(100);
		double end = System.currentTimeMillis();
		mw.result.setText("Result : "+sum);
		mw.time.setText("Run time: " + (end-start)/1000 + " s");
	}

}
